package es.uc3m.setichat.android;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class SeTIChatSQLiteHelper extends SQLiteOpenHelper {
	
	public static int SQL_VERSION = 5;

	public SeTIChatSQLiteHelper(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE contacts (telefono TEXT PRIMARY KEY, nick TEXT)");		
		db.execSQL("CREATE TABLE messages (idContact TEXT,origin TEXT,message TEXT,time TEXT, data varchar(255))");	
		db.execSQL("CREATE TABLE login (mobil TEXT,email TEXT,psw TEXT,nick TEXT)");
		db.execSQL("CREATE TABLE public_certificates (mobil TEXT, certificate TEXT, valid varchar(100))");
		db.execSQL("CREATE TABLE user_certificates (type varchar(3), certificate TEXT, password varchar(255))");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//		db.execSQL("DROP TABLE IF EXISTS contacts");
		db.execSQL("DROP TABLE IF EXISTS messages");
//		db.execSQL("DROP TABLE IF EXISTS login");
		db.execSQL("DROP TABLE IF EXISTS public_certificates");
		db.execSQL("DROP TABLE IF EXISTS user_certificates");
		
//		db.execSQL("CREATE TABLE contacts (telefono TEXT PRIMARY KEY, nick TEXT)");		
		db.execSQL("CREATE TABLE messages (idContact TEXT,origin TEXT,message TEXT,time TEXT, data varchar(255))");	
//		db.execSQL("CREATE TABLE login (mobil TEXT,email TEXT,psw TEXT,nick TEXT)");
		db.execSQL("CREATE TABLE public_certificates (mobil TEXT, certificate TEXT, valid varchar(100))");
		db.execSQL("CREATE TABLE user_certificates (type varchar(3), certificate TEXT, password varchar(255))");
	}

}
